package services

import (
	"jlpay-sdk-go/pkg/jlpay/core"
	"jlpay-sdk-go/pkg/jlpay/models"
)

// FundDeferredService 资金延期服务
type FundDeferredService struct {
	*BaseService
}

// NewFundDeferredService 创建资金延期服务
func NewFundDeferredService(config *core.Config) *FundDeferredService {
	return &FundDeferredService{
		BaseService: NewBaseService(config),
	}
}

// QueryDeferredActivation 查询资金管控状态
func (s *FundDeferredService) QueryDeferredActivation(request *models.DeferredActivationQueryRequest) (*models.DeferredActivationQueryResponse, error) {
	response := models.NewDeferredActivationQueryResponse()
	err := s.Post(request, response, "/open/fund/deferred/activation/query")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// OpenDeferredActivation 开通资金管控
func (s *FundDeferredService) OpenDeferredActivation(request *models.DeferredActivationOpenRequest) (*models.DeferredActivationOpenResponse, error) {
	response := models.NewDeferredActivationOpenResponse()
	err := s.Post(request, response, "/open/fund/deferred/activation/open")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// CloseDeferredActivation 关停资金管控
func (s *FundDeferredService) CloseDeferredActivation(request *models.DeferredActivationCloseRequest) (*models.DeferredActivationCloseResponse, error) {
	response := models.NewDeferredActivationCloseResponse()
	err := s.Post(request, response, "/open/fund/deferred/activation/close")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// QueryFundFlow 查询资金流水
func (s *FundDeferredService) QueryFundFlow(request *models.FundFlowQueryRequest) (*models.FundFlowQueryResponse, error) {
	response := models.NewFundFlowQueryResponse()
	err := s.Post(request, response, "/open/fund/deferred/order/query")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// FreezeFund 冻结资金
func (s *FundDeferredService) FreezeFund(request *models.FundFreezeRequest) (*models.FundFreezeResponse, error) {
	response := models.NewFundFreezeResponse()
	err := s.Post(request, response, "/open/fund/deferred/order/freeze")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// UnfreezeFund 解冻资金
func (s *FundDeferredService) UnfreezeFund(request *models.FundUnfreezeRequest) (*models.FundUnfreezeResponse, error) {
	response := models.NewFundUnfreezeResponse()
	err := s.Post(request, response, "/open/fund/deferred/order/unfreeze")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// RefreezeFund 续冻资金
func (s *FundDeferredService) RefreezeFund(request *models.FundRefreezeRequest) (*models.FundRefreezeResponse, error) {
	response := models.NewFundRefreezeResponse()
	err := s.Post(request, response, "/open/fund/deferred/order/refreeze")
	if err != nil {
		return nil, err
	}
	return response, nil
}
